<template>
	<view class="mySuggestion-page">
		<head-box></head-box>

		<view class="mySuggestion-page-main tab-botton">
      <view class="mySuggestion-page-main-item" v-if="item.adviseStatus>-1" v-for="(item, index) in list" :data-id="item.id">
        <view>
          <view class="mySuggestion-page-main-item-header">
            <view class="_item-header-title"><text>{{item.gpinfoName}}</text></view>
            <view :class="item.adviseStatus == 3 ? '_item-header-badge _item-header-badge-a' :  '_item-header-badge _item-header-badge-b' "><text class="yhf" v-if="item.adviseStatus == 3">已回复</text><text v-if="item.adviseStatus != 3">待回复</text></view>
          </view>
          <view class="mySuggestion-page-main-item-content">
            <view class="mySuggestion-page-main-item-content-inner">
              <view class="_content-inner-img" style="display: none;"><image class="_img" src="../../static/img/logo2.png" mode="aspectFit"></image></view>
              <view class="_content-inner-detail">
                <view class="_content-inner-detail-item">
                  <view class="_content-inner-detail-item-badge"><text class="_content-inner-detail-item-badge-text">我的信息</text></view>
                  <view class="_content-inner-detail-item-info">
                    <text>{{item.adviseContent}}</text>
                  </view>
                </view>
                <view class="_content-inner-detail-item" v-if="item.adviseStatus >= 3">
                  <view class="_content-inner-detail-item-badge _content-inner-detail-item-badge-bottom"><text class="_content-inner-detail-item-badge-text">回复信息</text></view>
                  <view class="_content-inner-detail-item-info">
                    <text> {{item.adviseResult}}</text>
                  </view>
                </view>
              </view>
            </view>
          </view>
          <view class="mySuggestion-page-main-item-bottom">
            <view class="mySuggestion-page-main-item-bottom-text"><text>提问时间：{{item.createTime}}</text></view>
            <sx-rate :value="item.commentStar"   v-if="item.adviseStatus==5" />
            <button  @tap="$handleLink('/pages/myevaluation/myevaluation?type=2&id='+item.id)" type="warn" size="mini" v-if="item.adviseStatus==3">未评价</button>
            <button  @tap="Cancel(item.id)" type="warn" size="mini" v-if="item.adviseStatus < 3">撤回</button>
          </view>
        </view>
      </view>
      <u-loadmore :status="status" :icon-type="iconType" @loadmore="loadmore" />
    </view>

		<tabs-box></tabs-box>
	</view>
</template>

<script>

	import { gpUseradviselist,gpGpinfo,gpUseradviseCancel } from '@/api/group';
	export default {
		data() {
			return {
				pageSize: 10,//每页多少条
				pageNo:1,//第几页
				list:[],//数组
        status: 'loadmore', //加载的状态
        iconType: 'flower', //加载图标样式
        isLoading: false, //是否要加载数据
			};
		},

		onLoad() {
			if(!uni.getStorageSync("token"))
			{

				uni.navigateTo({
					url:"../login/login"
				})
				return;
			}
		},
		onShow() {
      // #ifdef H5
      console.log('分享')
      this.$wxSetShare()
      // #endif
			this.getList()
		},
		methods:{
			Cancel(id)
			{
				var that = this
				gpUseradviseCancel(id).then(res => {
					console.log(res);
					if(res.success)
					{
						that.getList()
					}
				});
			},
      loadmore() {
        // 每次出发该方法，都要使页数加一
        this.pageNo++
       this.getList()
      },
			getList()
			{
				var that = this
        if (this.isLoading) {
          return
        }
        this.isLoading = true
        this.status = 'loading'
				let params = {
          pageSize:that.pageSize,pageNo:that.pageNo,
				  "column": "create_time","order": "desc"}
        uni.showLoading({
          title: '活动列表加载中...',
        })
				gpUseradviselist(params).then(res => {
          const {
            code,
            result: { records: list, total },
          }= res
          if(code===200)
					{
            this.isLoading = false
            uni.hideLoading()
            if (!list.length) {
              this.status = 'nomore'
            }
            else {
              this.status = 'loadmore'
              list.map(ele=>{
                var n = {id:ele.id,adviseStatus:ele.adviseStatus,adviseResult:ele.adviseResult,createTime:ele.createTime,gpinfoName:'',adviseContent:ele.adviseContent,commentStar:ele.commentStar}
                if(ele.gpinfoId!=''){
                  gpGpinfo(ele.gpinfoId).then(res => {
                    if(res.code==200)
                    {
                      n.gpinfoName = res.result.gpinfoName;
                    }
                  });
                }
                this.list.push(n)
              })
              if (this.list.length >= total) {
                this.status = 'nomore'
              }
            }
					}
          else {
            this.status = 'nomore'
          }
				});
			}
		},
    //加载到底部进行请求新的数据
    onReachBottom() {
      if (this.status === 'loadmore') {
        this.loadmore()
      }
    },
	}
</script>

<style lang="scss">
	page {
	        height: 100%;
	}
	.mySuggestion-page{
		width: 100%;
		box-sizing: border-box;
		padding-bottom: 160rpx;
		background-color: #efeff4;
		line-height: 42rpx;
		min-height: 100%;
		.mySuggestion-page-main{
			width: 100%;
			padding: 0 20rpx;
			box-sizing: border-box;
			min-height: 110%;
			.mySuggestion-page-main-item{
				width: 100%;
				border-radius: 4rpx;
				background-color: white;
				background-clip: padding-box;
				box-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.3);
				margin-top: 30rpx;
				.mySuggestion-page-main-item-header{
					position: relative;
					display: -webkit-box;
					display: -webkit-flex;
					display: flex;
					min-height: 88rpx;
					padding: 20rpx 30rpx;
					box-sizing: border-box;
					-webkit-box-pack: justify;
					-webkit-justify-content: space-between;
					justify-content: space-between;
					-webkit-box-align: center;
					-webkit-align-items: center;
					align-items: center;
					font-size: 34rpx;
					border-radius: 4rpx 4rpx 0 0;
					border-bottom: 1px solid rgba(200,199,204,0.5);
					._item-header-title{

					}
					._item-header-badge{
						font-size: 12px;
						line-height: 1;
						display: inline-block;
						padding: 3px 6px;
						color: #333;
						border-radius: 100px;
						background-color: rgba(0, 0, 0, .15);
					}
					._item-header-badge-a{
						color: #fff;
						background-color: #4cd964;
					}
					._item-header-badge-b{
						color: #fff;
						background-color: #f0ad4e;
					}
				}
				.mySuggestion-page-main-item-content{
					font-size: 28rpx;
					position: relative;
					.mySuggestion-page-main-item-content-inner{
						position: relative;
						padding: 30rpx;
						box-sizing: border-box;
						display: flex;
						flex-wrap: nowrap;
						justify-content: flex-start;
						._content-inner-img{
							width: 160rpx;
							height: 160rpx;
							._img{
								width: 100%;
								height: 100%;
							}
						}
						._content-inner-detail{
							width: calc(100% - 0rpx);
							._content-inner-detail-item{
								._content-inner-detail-item-badge{
									margin-left: 20rpx;
									._content-inner-detail-item-badge-text{
										margin: 0 10rpx;
										font-size: 24rpx;
										padding: 10rpx 20rpx;
										background-color: #F0AD4E;
										color: #fff;
										border-radius: 40rpx;
										box-sizing: border-box;
									}
								}
								._content-inner-detail-item-badge-bottom{
									margin-top: 40rpx;
								}
								._content-inner-detail-item-info{
									text-indent: 2em;
									padding: 20rpx 0 0 20rpx;
									box-sizing: border-box;
								}
							}
						}
					}
				}
				.mySuggestion-page-main-item-bottom{
					position: relative;
					display: -webkit-box;
					display: -webkit-flex;
					display: flex;
					min-height: 88rpx;
					padding: 20rpx 30rpx;
					box-sizing: border-box;
					-webkit-box-pack: justify;
					-webkit-justify-content: space-between;
					justify-content: space-between;
					-webkit-box-align: center;
					-webkit-align-items: center;
					align-items: center;
					border-top: 1px solid rgba(200,199,204,0.5);
					.mySuggestion-page-main-item-bottom-text{
						color: #6d6d72;
						border-radius: 0 0 4rpx 4rpx;
						font-size: 28rpx;
					}
				}
			}
		}
	}
</style>
